<template>
  <div class="con">
    <!-- 放置内容区 -->
    <div class="contbox6_10">
      <!-- 机构列表 -->
      <p class="titlelist6_10 titles">
        机构管理
        <span style="color: #999; font-size: 16px">
          &nbsp;&nbsp;
          <span style="font-size: 16px; color: #2f2c29">/</span>
          &nbsp;&nbsp; </span
        >渠道链接
      </p>
      <div class="content">
        <div class="sousuojg6_10">
          <el-form ref="form" :model="form" label-width="80px">
            <div>
              <el-form-item label="机构名称" style="float: left">
                <el-input v-model="form.officeName" placeholder="请输入机构名称" :maxlength="30"></el-input>
              </el-form-item>
              <el-form-item label="机构ID" style="float: left">
                <el-input
                placeholder="请输入机构ID"
                  v-model="form.officeUid"
                  style="width: 200px"
                ></el-input>
              </el-form-item>
            </div>
            <div class="clearfix">
              <el-form-item label="机构类型" style="float: left">
                <el-select v-model="form.agtType" placeholder="请选择结构类型">
                  <el-option
                    v-for="item in memberType"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="业务类型" style="float: left">
                <el-select
                  v-model="form.busUid"
                  @change="memberOffice"
                  placeholder="请选择业务类型"
                >
                  <el-option
                    v-for="items in bussinessType"
                    :key="items.uid"
                    :label="items.busName"
                    :value="items.uid"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="业务品牌" style="float: left">
                <el-select v-model="form.channelUid" placeholder="请选择业务品牌">
                  <el-option
                    v-for="item1 in vipTypeOptions"
                    :key="item1.uid"
                    :label="item1.channelName"
                    :value="item1.uid"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="推广名称" style="float: left">
                <el-input v-model="form.typeName" placeholder="请输入推广名称"></el-input>
              </el-form-item>
              <el-form-item label="状态" style="float: left">
                <el-select v-model="form.status" placeholder="请选择状态">
                  <el-option label="全部" value></el-option>
                  <el-option label="启用" value="0"></el-option>
                  <el-option label="停用" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="添加时间" style="float: left">
                <el-date-picker
                  class="time"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="开始日期"
                  v-model="form.startDate"
                ></el-date-picker>
                <div class="times">至</div>
                <el-date-picker
                  class="time"
                  v-model="form.endDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="结束时间"
                ></el-date-picker>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="buttons">
          <el-button
            v-if="isAuth('mechanismSearch')"
            type="primary"
            @click="onSubmit"
            >搜索</el-button
          >
          <el-button v-if="isAuth('mechanismReset')" @click="rest"
            >重置</el-button
          >
          <!-- <el-button
            class="butt"
            style="float: left; margin-left: 40px"
            type="primary"
            icon="el-icon-plus"
            v-if="isAuth('mechanismAdd')"
            @click="onnew(0)"
            >创建机构</el-button
          > -->
        </div>

        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
          stripe
          border
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '0px' }"
          style="width: 98%; margin-bottom: 20px; margin-left: 20px"
        >
          <!-- <el-table-column type="selection" min-width="55"></el-table-column> -->
          <el-table-column
            prop="officeUid"
            label="机构ID"
            width="180"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            show-overflow-tooltip
            label="机构名称"
            min-width="150"
            prop="officeName"
          ></el-table-column>
          
          <!-- <el-table-column prop="agtType" label="机构类型" width="120"></el-table-column> -->
          <el-table-column
            prop="agtType"
            label="机构类型"
            min-width="80"
            show-overflow-tooltip
          ></el-table-column>

          <!-- <el-table-column
            v-if="jurisdictionn == 2"
            prop="hkproCode"
            label="服务商编号"
            min-width="110"
            show-overflow-tooltip
          ></el-table-column> -->

          <el-table-column
            prop="busName"
            label="业务类型"
            show-overflow-tooltip
            min-width="100"
          ></el-table-column>
          <el-table-column
            prop="channelName"
            show-overflow-tooltip
            label="业务品牌"
            min-width="110"
          ></el-table-column>
          <el-table-column
            prop="typeName"
            label="推广名称"
            show-overflow-tooltip
            min-width="100"
          ></el-table-column>
          <el-table-column
            prop="busUrl"
            show-overflow-tooltip
            label="推广链接"
            width="400"
          ></el-table-column>
          <el-table-column
            prop="createDate"
            label="添加时间"
            show-overflow-tooltip
            width="160"
          ></el-table-column>

          <el-table-column prop="status" label="状态" width="80">
            <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.status"
                  inactive-value="1"
                  active-value="0"
                  @change="changeJur(scope.row.id)"
                  active-color="#56BB8A"
                  inactive-color="#C0C4CC"
                >
                </el-switch>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          style="text-align: right;"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="form.page"
          :page-sizes="[20, 50, 100]"
          :page-size="form.number"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalNum"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import https from "../../plugins/https.js";
import { CompareDate } from "../../assets/js/commion";
export default {
  data() {
    return {
      totalNum: 0,
      tableData: [{}],
      //业务类型
      bussinessType: [],
      // 业务品牌
      vipTypeOptions: [],
      memberType: [
        {
          value: "",
          label: "全部"
        },
        {
          value: "0",
          label: "OEM"
        },
        {
          value: "3",
          label: "渠道机构"
        }
      ],
      form: {
        page: 1,
        number: 20,
        officeName: "",
        officeUid: "",
        agtType: "",
        busUid: "",
        channelUid: "",
        typeName: "",
        toOfficeName: "",
        status: "",
        startDate: "",
        endDate: ""
      }
    };
  },
  created() {
    this.getData();
    https
      .getAllBusInfo({ status: "0" })
      .then(res => {
        console.log(res);
        this.bussinessType = res.data.data;
      })
      .catch(err => {});
  },
  methods: {
    // 控制这个权限
    changeJur(val) {
      https.changeOfficeLinkStatus({ id: val }).then(res => {
        if (res.data.code == "0000") {
          this.getData();
        } else {
          layer.open({
            content: res.data.msg,
            skin: "msg",
            time: 2 //1秒后自动关闭
          });
        }
      }).catch(err=>{})
    },
    // 重置
    rest() {
      this.form = {
        page: 1,
        number: 20,
        officeName: "",
        officeUid: "",
        agtType: "",
        busUid: "",
        channelUid: "",
        typeName: "",
        toOfficeName: "",
        status: "",
        startDate: "",
        endDate: ""
      };
      this.getData();
    },
    // 校验时间的一个方法
    warrys() {
      layer.open({
        content: "结束时间不能早于开始时间",
        skin: "msg",
        time: 2 //1秒后自动关闭
      });
    },
    // 搜索
    onSubmit() {
      this.form.page = 1;
      let bool = CompareDate(this.form.startDate, this.form.endDate);
      if (this.form.startDate != "" && this.form.endDate != "") {
        if (bool) this.getData();
        else this.warrys();
      } else {
        this.getData();
      }
    },
    // 列表
    getData() {
      var _this = this;
      https
        .officeLinklist(_this.form)
        .then(function(d) {
          console.log("下面是列表数据");
          console.log(d);
          if (d.data.code == "0000") {
            _this.tableData = d.data.data;
            for (var s = 0; s < _this.tableData.length; s++) {
              _this.tableData[s].agtType =
                _this.tableData[s].agtType == 0
                  ? "OEM"
                  : _this.tableData[s].agtType == 1
                  ? "普通代理"
                  : "渠道机构";
            }

            _this.totalNum = d.data.total;
          } else {
            layer.open({
              content: d.data.msg,
              skin: "msg",
              time: 2 //1秒后自动关闭
            });
          }
        })
        .catch(function(error) {
          //axios请求失败回调
          console.log(error);
        });
    },
    // 业务类型
    memberOffice(val) {
      https
        .getBusChannel({ busUid: val })
        .then(res => {
          this.vipTypeOptions = res.data.data;
        })
        .catch(err => {});
    },
    //分页类型
    handleSizeChange(val) {
      this.form.number = val; //动态改变
      this.form.page = 1;
      this.getData();
    },
    handleCurrentChange(val) {
      /* alert(`当前页: ${val}`);*/

      this.form.page = val; //动态改变
      this.getData();
    }
  }
};
</script>

<style scoped>
/deep/ .el-container[data-v-4d4a7ce2] {
  background: #f5f7fa !important;
  height: 100% !important;
}
.con {
  position: relative;
}
/* 单独样式 */
.contbox6_10 {
  width: 100%;
  /*  height: 87.5vh; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.titlelist6_10 {
  position: absolute;
  padding-left: 20px;
  height: 36px;
  background: #fff;
  width: 100%;
  float: left;
  line-height: 36px;
  font-size: 16px;
  color: #222;
  border-bottom: 1px solid #ebeef5;
  border-top: 1px solid #ebeef5;
}
.content {
  float: left;
  margin-top: 200px;
  margin-bottom: 0px;
  margin: 36px 0px 0px;
  height: calc(100vh - 100px - 26px);
  background: #fff;
}
.buttons {
  width: 100%;
  float: left;

  border: none;
  margin-bottom: 10px;
}
.buttons .el-button {
  float: left;
  padding: 7px;
}
.sousuojg6_10 {
  float: left;
  box-sizing: border-box;
  font-size: 16px;
  color: #222;
  box-sizing: border-box;
  border-radius: 5px;
}
.el-form-item {
  margin-bottom: 10px;
}
.time {
  width: 136px !important;
}
.time > .el-input__inner {
  width: 100% !important;
}
.times {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.el-col-1 {
  width: 3%;
}
.nav {
  width: 100%;
  display: flex;
}
.clearfix:after {
  display: block;
  height: 0;
  clear: both;
  content: ".";
  visibility: hidden;
}
.titles {
  font-size: 16px;
  /* font-weight: bold; */
}
.buttons > .el-button {
  width: 100px;
  padding: 7px;
  height: 32px;
}
.subTtile {
  font-size: 18px;
  font-weight: bold;
}
.titlesSub {
  font-size: 18px;
  font-weight: bold;
  width: 80px;
  display: inline-block;
}
.exports {
  color: #409eff;
  border-color: #409eff;
}

.butt {
  background: #f5f7fa;
  color: #409eff;
}
/deep/ .el-textarea__inner {
  height: 160px;
}
</style>
